import { $ } from "../modules/public.js";
import ajax from "../modules/ajax.js";
import toast from "../modules/toast.js";

$(".btn").onclick = function(){
  ajax({
    url:"http://localhost:3000/register",
    method:"post",
    data:{
      tel: $(".tel").value
    }
  }).then(res=>{
    res = JSON.parse(res);
    if(res.code === 0){
      toast({
        type:"error",
        title:"手机号重复",
        close:()=>{
          $(".tel").value = "";
          $(".tel").focus();
        }
      })
    }else{
      toast({
        type:"success",
        title:"注册成功",
        close:()=>{
          sessionStorage.setItem("tel", $(".tel").value);
          location.assign("./login.html");
        }
      })
    }
  })
}